package de.home.develop.firstgame.logic
{
	import flash.events.*;
	import flash.geom.*;
	import flash.media.*;
	import flash.net.*;
	import flash.utils.*;
	
	import mx.collections.ArrayCollection;
	import mx.core.*;
	
	public class Level
	{
		
		protected static const BACKGROUND_INDEX:Number = 0;
		
		protected var backgroundSet:Boolean = false;
		protected var ballSet:Boolean = false;		
		protected static var instance:Level = null;																					
		protected var levelElementGraphics:ArrayCollection = new ArrayCollection();						
				
								
		protected var enemyElementGraphics:ArrayCollection = new ArrayCollection();	
		protected var timeToNextCloud:Number = 0;		
		protected var players:ArrayCollection = new ArrayCollection(); 
		
				
		
		/**
		 * 
		 * 
		 * */
		static public function get Instance():Level		
		{		
			if ( instance == null )				
				instance = new Level();		
			return instance;		
		}
		
			
		/**
		 * 
		 * 
		 * */
		public function Level(caller:Function = null )	
		{			
			if ( Level.instance != null )				
				throw new Error("Only one Singleton instance should be instantiated");
			levelElementGraphics.addItem(ResourceManager.Strand1Graphics);
			
			
		}
		
		/**
		 * 
		 * 
		 * */
		public function startup():void		
		{			
			
			for each (var player:Player in players)			
			{				
				player.startupPlayer();
				
			}		
			
			
			
			
		}
		
		public function shutdown():void			
		{
			
		
			
		}
		
		
		/**
		 * 
		 * 
		 * */
		public function enterFrame(dt:Number):void		
		{	
			if(!backgroundSet)
			{
				var backgroundGraphics:GraphicsResource = levelElementGraphics.getItemAt(BACKGROUND_INDEX) as GraphicsResource;
				var backgroundLevel:BackgroundLevelElement = BackgroundLevelElement.pool.ItemFromPool as BackgroundLevelElement;			
				backgroundLevel.startupBackgroundLevelElement(backgroundGraphics,new Point(0,0),ZOrders.BackgoundZOrder,0);
				backgroundSet = true;
			}
																																						
			
		}						
		
		public function getPlayer():ArrayCollection
		{
			return instance.players;
		}
		
	}
}